﻿using System.Collections.Generic;
using Newtonsoft.Json;

namespace ZilLion.Service.WeChatMall.Domain.Entitys.GsInfo
{
    public class GsFrontTreeDto
    {
        [JsonProperty("categoryId")]
        public long CategoryId { get; set; }

        [JsonProperty("name")]
        public string Name { get; set; }

        [JsonProperty("type")]
        public string Type { get; set; }

        [JsonProperty("foods")]
        public IList<GsFrontDto> Foods { get; set; }

        public static GsFrontTreeDto Convert(GsGroupEntity group, IList<GsFrontDto> list)
        {
            foreach (var good in list)
                good.CategoryId = group.GroupId;
            var dto = new GsFrontTreeDto
            {
                Name = group.GroupName,
                Type = group.GroupType,
                Foods = list
            };

            return dto;
        }
    }

    public class GsFrontDto
    {
        [JsonProperty("categoryId")]
        public long CategoryId { get; set; }

        [JsonProperty("foodId")]
        public long FoodId { get; set; }

        [JsonProperty("name")]
        public string Name { get; set; }

        [JsonProperty("price")]
        public decimal? Price { get; set; }

        [JsonProperty("oldPrice")]
        public decimal? OldPrice { get; set; }

        [JsonProperty("description")]
        public string Description { get; set; }

        [JsonProperty("sellCount")]
        public decimal? SellCount { get; set; }

        [JsonProperty("rating")]
        public int? Rating { get; set; }

        [JsonProperty("info")]
        public string Info { get; set; }

        //[JsonProperty("ratings")]
        //public FoodRatingEntity[] FoodRatingsEntity { get; set; }

        [JsonProperty("icon")]
        public string Icon { get; set; }

        [JsonProperty("image")]
        public string Image { get; set; }

        public static GsFrontDto Convert(GsBasicInfoEntity basic, GsExtraInfoEntity extra)
        {
            var dto = new GsFrontDto
            {
                Name = basic.GsName,
                SellCount = extra?.GsSellCount,
                Description = basic.GsDescription,
                FoodId = basic.GsId,
                Icon = basic.GsIcon,
                Image = basic.GsImage,
                Info = basic.GsInfo,
                OldPrice = extra?.GsOldPrice,
                Price = basic.GsPrice,
                Rating = extra?.GsRating
            };

            return dto;
        }
    }

    public class FoodRatingEntity
    {
        [JsonProperty("username")]
        public string Username { get; set; }

        [JsonProperty("rateTime")]
        public long? RateTime { get; set; }

        [JsonProperty("rateType")]
        public int? RateType { get; set; }

        [JsonProperty("text")]
        public string Text { get; set; }

        [JsonProperty("avatar")]
        public string Avatar { get; set; }
    }
}